/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.integral.web.controller.manager;

import com.medusa.gruul.common.core.annotation.EscapeLogin;
import com.medusa.gruul.common.core.util.PageUtils;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.common.data.tenant.ShopContextHolder;
import com.medusa.gruul.integral.service.IIntegralGoodsService;
import com.medusa.gruul.integral.web.model.dto.manager.IntegralGoodsDto;
import com.medusa.gruul.integral.web.model.param.manager.IntegralGoodsParam;
import com.medusa.gruul.integral.web.model.vo.IntegralGoodVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 积分商品表 前端控制器
 * </p>
 *
 * @author xiaoq
 * @since 2019-11-19
 */
@RestController
@RequestMapping("/manager")
@Api(tags = "积分商品接口")
public class IntegralGoodsController {
    @Autowired
    private IIntegralGoodsService integralGoodsService;

    /**
     * 积分商品新增 (发布商品)
     *
     * @param integralGoodsDto 积分商品数据
     * @return
     */
    @PostMapping("/issue/integralGoods")
    @ApiOperation(value = "积分商品发布")
    public Result issueIntegralGoods(@RequestBody @Validated IntegralGoodsDto integralGoodsDto) {
        String shopId = ShopContextHolder.getShopId();
        integralGoodsService.addIntegralGoods(integralGoodsDto, shopId);
        return Result.ok();
    }


    /**
     * 根据积分商品id 删除积分商品 (逻辑删除)
     *
     * @param id 积分商品id
     * @return
     */
    @EscapeLogin
    @DeleteMapping("/delete/integralGoods/{id}")
    @ApiOperation(value = "删除积分商品")
    public Result deleteIntegralGoods(@ApiParam(value = "积分商品id", required = true) @PathVariable(name = "id") Long id) {
        integralGoodsService.deleteIntegralGoods(id);
        return Result.ok();
    }


    /**
     * 积分商品信息修改
     *
     * @param integralGoodsDto 积分商品信息
     * @return
     */
    @PutMapping("/update/integralGoods")
    @ApiOperation(value = "积分商品信息修改")
    public Result updateIntegralGoods(@RequestBody @Validated IntegralGoodsDto integralGoodsDto) {
        integralGoodsService.updateIntegralGoods(integralGoodsDto);
        return Result.ok();
    }


    /**
     * 获取积分商品的基础信息
     *
     * @param id 积分商品id
     * @return 积分商品基础信息
     */
    @GetMapping("/get/integralGoodsInfo")
    @ApiOperation(value = "单个积分商品基础信息")
    public Result<IntegralGoodVo> getIntegralGoodsInfo(@ApiParam(value = "积分商品id", required = true) Long id) {
        IntegralGoodVo integralGoodsInfo = integralGoodsService.getIntegralGoodsInfo(id);
        return Result.ok(integralGoodsInfo);
    }


    /**
     * 积分商品上下架
     *
     * @param id     积分商品id
     * @param status 状态值
     * @return
     */
    @PutMapping("/update/integralGoods/status")
    @ApiOperation(value = "积分商品上下架")
    public Result updateIntegralGoodsStatus(@ApiParam(value = "积分商品id", required = true) Long id,
                                            @ApiParam(value = "积分商品状态") Integer status) {
        integralGoodsService.updateIntegralGoodsStatus(id, status);
        return Result.ok();
    }


    /**
     * 积分商品批量上下架
     *
     * @param ids    积分商品ids
     * @param status 状态值 (上架或下架)
     * @return
     */
    @PutMapping("/update/batchIntegralGoods/{status}")
    @ApiOperation(value = "积分商品批量上下架")
    public Result updateBatchIntegralGoodsStatus(@ApiParam(value = "积分商品ids", required = true) @RequestBody Long[] ids,
                                                 @ApiParam(value = "状态值", required = true) @PathVariable("status") Integer status) {
        integralGoodsService.updateBatchStatus(ids, status);
        return Result.ok();

    }


    /**
     * 批量删除积分商品(逻辑删除)
     *
     * @param ids 积分商品ids
     * @return
     */
    @DeleteMapping("/delete/batch/integralGoods/{ids}")
    @ApiOperation(value = "批量删除积分商品")
    public Result deleteBatchIntegralGoods(
            @ApiParam(value = "积分商品ids", required = true) @RequestBody @PathVariable(name = "ids") Long[] ids) {
        integralGoodsService.deleteBatch(ids);
        return Result.ok();
    }


    /**
     * 积分商品信息列表
     *
     * @param integralGoodsParam 查询条件
     * @return 符合条件的积分商品数据
     */
    @GetMapping("get/integralGoods/List")
    @ApiOperation(value = "积分商品信息")
    @EscapeLogin
    public Result<PageUtils<IntegralGoodVo>> getIntegralGoods(IntegralGoodsParam integralGoodsParam) {
        PageUtils<IntegralGoodVo> pageUtils = new PageUtils(integralGoodsService.selectIntegralGoodsList(integralGoodsParam));
        return Result.ok(pageUtils);
    }
}
